package com.engine.salary.entity.siaccount.bo;


import com.engine.salary.entity.siaccount.dto.InsuranceAccountBatchListDTO;
import com.engine.salary.entity.siaccount.po.InsuranceAccountBatchPO;
import com.engine.salary.enums.siaccount.BillStatusEnum;
import com.engine.salary.mapper.taxagent.TaxAgentMapper;
import com.engine.salary.util.SalaryEntityUtil;
import com.engine.salary.util.SalaryEnumUtil;
import com.engine.salary.util.db.MapperProxyFactory;
import org.apache.commons.collections.CollectionUtils;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author weaver_cl
 * @Description:
 * @Date 2022/4/11
 * @Version V1.0
 **/
public class InsuranceAccountBO {

//    public static Wrapper<InsuranceAccountInspectPO> buildInspectListWrapper(String billMonth, String tenantKey) {
//        LambdaQueryWrapper<InsuranceAccountInspectPO> lambdaQueryWrapper = Wrappers.lambdaQuery();
//        lambdaQueryWrapper.eq(InsuranceAccountInspectPO::getTenantKey, tenantKey);
//        lambdaQueryWrapper.eq(InsuranceAccountInspectPO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue());
//        lambdaQueryWrapper.eq(InsuranceAccountInspectPO::getBillMonth, billMonth);
//        return lambdaQueryWrapper;
//    }
//
//    public static Wrapper<InsuranceAccountBatchPO> buildBatchListWrapper(String startTime, String endTime, String tenantKey) {
//        LambdaQueryWrapper<InsuranceAccountBatchPO> lambdaQueryWrapper = Wrappers.lambdaQuery();
//        lambdaQueryWrapper.eq(InsuranceAccountBatchPO::getTenantKey, tenantKey);
//        lambdaQueryWrapper.eq(InsuranceAccountBatchPO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue());
//        if (StringUtils.isNotBlank(startTime)) {
//            lambdaQueryWrapper.ge(InsuranceAccountBatchPO::getBillMonth, startTime);
//        }
//        if (StringUtils.isNotBlank(endTime)) {
//            lambdaQueryWrapper.le(InsuranceAccountBatchPO::getBillMonth, endTime);
//        }
//        lambdaQueryWrapper.orderByDesc(InsuranceAccountBatchPO::getBillMonth);
//        return lambdaQueryWrapper;
//    }
//
    public static List<InsuranceAccountBatchListDTO> buildAccountBatchDTOList(Collection<InsuranceAccountBatchPO> list) {
        if (CollectionUtils.isEmpty(list)) {
            return Collections.emptyList();
        }
        return list.stream().map(e -> InsuranceAccountBatchListDTO.builder()
            .id(e.getId())
            .accountant(e.getAccountant())
            .billMonth(e.getBillMonth())
//            .billStatus(queryLabelId(e.getBillStatus()).getDefaultLabel())
            .billStatus(e.getBillStatus().toString())
            .fundNum(e.getFundNum())
            .fundPay(SalaryEntityUtil.thousandthConvert(e.getFundPay()))
            .lastTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(e.getUpdateTime()))
            .otherNum(e.getOtherNum())
            .otherPay(SalaryEntityUtil.thousandthConvert(e.getOtherPay()))
            .remarks(e.getRemarks())
            .socialNum(e.getSocialNum())
            .socialPay(SalaryEntityUtil.thousandthConvert(e.getSocialPay()))
            .paymentOrganization(e.getPaymentOrganization() != null ? MapperProxyFactory.getProxy(TaxAgentMapper.class).getById(e.getPaymentOrganization()).getName() : "")
            .paymentOrganizationId(e.getPaymentOrganization())
            .creator(e.getCreator())
            .opts(e.getOpts())
            .build()
        ).collect(Collectors.toList());
    }

    public static BillStatusEnum queryLabelId(Integer value) {
        return SalaryEnumUtil.enumMatchByValue(value, BillStatusEnum.values(), BillStatusEnum.class);
    }

//
//    public static Wrapper<InsuranceAccountDetailPO> buildBillWrapper(String billMonth, PaymentStatusEnum paymentStatusEnum, Long employeeId, String tenantKey) {
//        LambdaQueryWrapper<InsuranceAccountDetailPO> queryWrapper = Wrappers.lambdaQuery();
//        queryWrapper.eq(InsuranceAccountDetailPO::getTenantKey, tenantKey);
//        queryWrapper.eq(InsuranceAccountDetailPO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue());
//        queryWrapper.eq(InsuranceAccountDetailPO::getBillMonth, billMonth);
//        queryWrapper.eq(InsuranceAccountDetailPO::getPaymentStatus, paymentStatusEnum.getValue());
//        queryWrapper.orderByDesc(InsuranceAccountDetailPO::getUpdateTime);
//        return queryWrapper;
//    }
//
//    public static Wrapper<InsuranceAccountDetailPO> buildPersonBillWrapper(String startMonth, String endMonth, Long employeeId, String tenantKey) {
//        LambdaQueryWrapper<InsuranceAccountDetailPO> queryWrapper = Wrappers.lambdaQuery();
//        queryWrapper.eq(InsuranceAccountDetailPO::getTenantKey, tenantKey);
//        queryWrapper.eq(InsuranceAccountDetailPO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue());
//        queryWrapper.eq(InsuranceAccountDetailPO::getEmployeeId, employeeId);
//        if (StringUtils.isNotBlank(startMonth) && StringUtils.isNotBlank(endMonth)) {
//            queryWrapper.between(InsuranceAccountDetailPO::getBillMonth, startMonth, endMonth);
//        }
//        queryWrapper.orderByDesc(InsuranceAccountDetailPO::getBillMonth);
//        return queryWrapper;
//    }

}
